/// <reference path="../GeneratedArtifacts/viewModel.js" />
/// <reference path="../Scripts/c1ls-4.0.20141.30.js" />

if (typeof c1ls === "undefined") {
    window.location.href = "http://bit.ly/c1ls-nuget";
}

// http://bit.ly/c1ls-dropdown
//
myapp.DropDownFilter.Categories_render = function (element, contentItem) {

    var label = $("<label class='c1ls-label-text msls-label-text'/>");
    label.text(contentItem.displayName);
    label.appendTo($(element));

    var select = $("<select data-role='listview' class='msls-listview'/>");
    select.appendTo($(element));

    $(element).addClass("msls-leaf");

    contentItem.value.oncollectionchange = function () {
        var options = {
            defaultValue: 0,
            defaultText: "(Select a category)"
        };
        var items = c1ls.getDropDownContent(select, contentItem, options);
        select.html(items.join("\r\n"));
        select.val(0);
        select.trigger("change");
    };

    c1ls.renderControl(contentItem);
};

// http://bit.ly/c1ls-dropdown
//
myapp.DropDownFilter.Products_render = function (element, contentItem) {

    var label = $("<label class='c1ls-label-text msls-label-text'/>");
    label.text(contentItem.displayName);
    label.appendTo($(element));

    var select = $("<select data-role='listview' class='msls-listview'/>");
    select.appendTo($(element));

    $(element).addClass("msls-leaf");

    contentItem.value.oncollectionchange = function () {
        var options = {
            defaultValue: 0,
            defaultText: "(Select a product)"
        };
        var items = c1ls.getDropDownContent(select, contentItem, options);
        select.html(items.join("\r\n"));
        select.val(0);
        select.trigger("change");
    };

    c1ls.renderControl(contentItem);
};

// http://bit.ly/c1ls-radialgauge
//
myapp.DropDownFilter.Products_selectedItem_UnitsInStock_render = function (element, contentItem) {

    var div = $("<div/>");
    div.appendTo($(element));
    div.attr("style", "width: 200px; height: 200px");

    setTimeout(function () {
        div.wijradialgauge({
            value: contentItem.value,
            min: 0,
            max: 125,
            radius: "auto",
            startAngle: -45,
            sweepAngle: 270
        });
    }, 500);

    contentItem.dataBind("value", function (newValue) {
        div.wijradialgauge({ value: newValue });
    });
};

// http://bit.ly/c1ls-radialgauge
//
myapp.DropDownFilter.Products_selectedItem_UnitsOnOrder_render = function (element, contentItem) {

    var div = $("<div/>");
    div.appendTo($(element));
    div.attr("style", "width: 200px; height: 200px");

    setTimeout(function () {
        div.wijradialgauge({
            value: contentItem.value,
            min: 0,
            max: 100,
            radius: "auto",
            startAngle: -45,
            sweepAngle: 270
        });
    }, 500);

    contentItem.dataBind("value", function (newValue) {
        div.wijradialgauge({ value: newValue });
    });
};

// http://bit.ly/c1ls-rating
//
myapp.DropDownFilter.Products_selectedItem_ReorderLevel_render = function (element, contentItem) {

    var div = $("<div/>");
    div.appendTo($(element));

    div.wijrating({
        count: 6,
        min: 0,
        max: 30,
        totalValue: 30,
        disabled: true
    });

    contentItem.dataBind("value", function (newValue) {
        div.wijrating({
            value: newValue
        });
    });
};
